#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTranslator>
#include <QToolButton>
#include <QEvent>
#include <QPainter>
#include <QDateTime>
#include "dataprovider.h"
#include "mypwrctrl.h"
#include "mydisplaywidget.h"
#include "helpwin.h"
#include <QMessageBox>
#include <QProcess>

#include <QFileSystemWatcher>
#include <QDir>
#include <QFileInfo>
#include "autoupdata.h"
#include <QTimer>
#include <QLabel>


#define USE_EVENT_FILTER  0
namespace Ui {
class MainWindow;
}

// lbs 20170421


// lbs 20170421
Q_DECLARE_METATYPE(LANGUAGE)


//语言国际化

 typedef enum
{
    tr_MS_replace,
    tr_MS_Init,
    tr_MS_twoFiber,
    tr_MS_rightFiber,
    tr_MS_leftFiber,
    tr_MS_leftBad,
    tr_MS_rightBad,
    tr_MS_bothBad,
    tr_MS_power,
    tr_MS_closeSys,
    tr_MS_success,
    tr_MS_failure,

    tr_enum_weld,
    tr_auto,
    tr_manual,
    tr_continuous,
    tr_alignment,
    tr_suspension,
    tr_openCurrent,


    tr_enum_Heating,
    tr_heatingAuto,
    tr_heatingManu,


    tr_enum_speed,
    tr_fast,
    tr_precision,

    tr_enum_system,
    tr_weld,
    tr_propulsion,
    tr_proSpeed,
    tr_endAngle,
    tr_manualSpeed,
    tr_dischargeValue,
    tr_discharge,
    tr_singleMode,
    tr_multimode,
    tr_preWeldTime,
    tr_preWeldStrength,
    tr_weldTime,
    tr_weldStrength,
    tr_heatingSetting,
    tr_heatingTime,
    tr_machineSettings,
    tr_tensionTest,
    tr_Vtype,
    tr_open,
    tr_close,
    tr_menuTransparency,
    tr_language,
    tr_chinese,
    tr_english,
    tr_timeSetting,
    tr_maintenance,
    tr_save,
    tr_restore,
    tr_replace,
    tr_dischargeTimes,
    tr_self_test,
    tr_energy,
    tr_standby,
    tr_shutdown,
    tr_clear,
    tr_userGuide,
    tr_operation,
    tr_guide,
    tr_video,

    tr_enum_record,
    tr_details,
    tr_statistics,
    tr_success,
    tr_failure,

    tr_currentState,

    tr_hardwareV,
    tr_softwareV,
    tr_equipmentNumber,

    tr_dischargeNormal,
    tr_dischargeTooStrong,
    tr_dischargeTooWeak,
    tr_fromLeft,
    tr_fromRight,
    tr_dischargeAnomaly,
    tr_positionAdjustment,
    tr_intensityAdjustment,
    tr_confirm,
    tr_prompt,

    tr_engineering,
    tr_saveSettings,
    tr_initialization,
    tr_rapidAdvance,
    tr_precisionPropulsion,
    tr_precisionAlignment,
    tr_suspend,
    tr_dischargeWelding,
    tr_saveTestResults,
    tr_estimatedLoss,
    tr_weldFailure,

    tr_slotDetection,
    tr_endReport,
    tr_free,
    tr_spacing

}LanguageSetting;

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:

    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void setLanguage();    // lbs 20170421
    void setTranslator(QTranslator* translator);    // lbs 20170421
    QString getLanguageTr(LanguageSetting index);



public slots:
    void refreshUI();
    void refreshAGCSet();
    void refreshStatBar();
    void refreshDynamicUI(int id);
    void flashHeatingIcon();
    void ButtonBeep(); //蜂鸣器
    void directoryUpdated(const QString &path);
    void displayComs();
    void sysreboot();
    void powerOff(int);
    void BTPressEvent();
    void UnlockPermissions( );


private:

    Ui::MainWindow *ui;

    void setTButtonFocusStyle(QToolButton*,QEvent::Type);
    bool handleFocusChange(QToolButton*,QEvent*);

    void enterStateMode();
    void enterEditMode();
    void initButtons();
    void AdjustCmos(char *agc_aec,int dir);
    void selectCheck();
    //系统值
    MyDisplayWidget* bgWidget;
    DataProvider* dataProvider;
    //MyPwrCtrl* mypwrctrl;
    helpWin *my_helpWin;
    helpWin *my_messageBox;

     MyDisplayWidget* frontWidgetBottom ;
     MyDisplayWidget* frontWidgetTop;

    int  HeatCntr;
    bool flashAlt;
    bool ifStateMode;
    int  RecordIdx;
    bool my_tb5Enable;

    void refreshRecord(int id);
    void upRefreshRecord(int id);
    void downRefreshRecord(int id);
    void refreshStatistic(int id);
    void refreshMeltMode(int id);
    void refreshHeatMode(int id);
    void refreshSpeedMode(int id);


    void translateUI();
    void initSelectedButtons();  //  lbs 2017/5/8
    //  lbs 20170421
    void switchLanguage(LANGUAGE language);
    void refreshLanguage();
    void setPermissions(bool);
    LANGUAGE my_current_language;
    QTranslator *my_translator;
    QString t_recordClean;
    int my_dischargeCount;
    int my_saveSettingCount;
    QFileSystemWatcher *my_sysWatcher;
    autoUpdata *my_autoUpdata;
    bool my_displayCpuTemp;
    bool my_MeltDoneenable;
    bool my_displayAlarm;

    int my_alarmCount;
    int my_elecCount;
    QTimer* refreshBright;
    bool my_objectBGTran;
    int my_tempCount;

    void alarmSlot();
    bool my_StandbyEnable;
    int  my_StandbyCount;
    int my_TurnOffCount;
    bool my_closGZEnable;
    bool my_AGCrestEn;
    bool my_openGZKeysEnable;


    bool my_heatingEnable;
    int my_batCount;

protected:

    bool eventFilter(QObject *, QEvent*);
    void focusInEvent(QFocusEvent *);
    void focusOutEvent(QFocusEvent *);
    //void paintEvent(QPaintEvent *);
    void keyPressEvent(QKeyEvent *);
    void keyReleaseEvent ( QKeyEvent * event );
    void changeEvent(QEvent *event);  // lbs 20170421





};

#endif // MAINWINDOW_H
